//
//  BGSellerOrderCell.m
//  bigMall
//
//  Created by ios on 16/9/7.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGSellerOrderCell.h"
#import "BGShellerOrderListModel.h"
static NSString *const reuseIdentify = @"cell";
@implementation BGSellerOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}
- (void)layoutSubviews {
   
    for (UIView *v in self.contentView.subviews) {
        
        if ([v isKindOfClass:[UIView class]]) {
            [v removeFromSuperview];
        }
    }
    //修饰条
    UIView *xiushi = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 10)];
    xiushi.backgroundColor = dockwhite_;
    [self.contentView addSubview:xiushi];
    
    //订单号
    UILabel *orderLab = [[UILabel alloc] initWithFrame:CGRectMake(21, xiushi.bottom + 10, 100, 21)];
    orderLab.text = [NSString stringWithFormat:@"订单号：%@",self.orderStr];
    orderLab.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:orderLab];
    
    //type
    UILabel *typeLab = [[UILabel alloc] initWithFrame:CGRectMake(xiushi.width - 21 - 160, orderLab.y, 160, 21)];
    typeLab.font = [UIFont systemFontOfSize:16];
    typeLab.text = self.typeStr;
    typeLab.textColor = [UIColor redColor];
    typeLab.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:typeLab];
    
    //小灰线
    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, typeLab.bottom + 10, xiushi.right, 1)];
    v1.backgroundColor = dockwhite_;
    [self.contentView addSubview:v1];
    
    //类别啊
    UILabel *leibieLab = [[UILabel alloc] initWithFrame:CGRectMake(21, v1.bottom + 10, 100, 21)];
    leibieLab.text = self.leibieStr;
    leibieLab.font = [UIFont boldSystemFontOfSize:16];
    [self.contentView addSubview:leibieLab];
    
    //time
    UILabel *timeLab = [[UILabel alloc] initWithFrame:CGRectMake(xiushi.width - 21 - 150, leibieLab.y, 150, 21)];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[self.timeStr intValue]];
    NSDateFormatter *fat = [[NSDateFormatter alloc] init];
    [fat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *str = [fat stringFromDate:date];
    timeLab.text = str;
    timeLab.textAlignment = NSTextAlignmentRight;
    timeLab.textColor = lightGray_;
    timeLab.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:timeLab];
    
    //单价啊
    UILabel *priceLab = [[UILabel alloc] initWithFrame:CGRectMake(21, leibieLab.bottom + 10, 151, 21)];
    priceLab.font = [UIFont systemFontOfSize:16];
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"单价：%@元/吨",self.priceStr]];
    [attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3, attributeStr.length - 3)];
    priceLab.attributedText = attributeStr;
//    CGSize prcieSize = [priceLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:priceLab.font,NSFontAttributeName,nil]];
//    priceLab.bounds = CGRectMake(0, 0, prcieSize.width, 21);
    [self.contentView addSubview:priceLab];
    
    //小竖线
    UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(priceLab.right + 5, priceLab.y, 1, 21)];
    v2.backgroundColor = dockwhite_;
    [self.contentView addSubview:v2];
    
    //数量啊
    UILabel *numberLab = [[UILabel alloc] initWithFrame:CGRectMake(v2.right + 16, leibieLab.bottom + 10, 140, 21)];
    numberLab.font = [UIFont systemFontOfSize:16];
    NSMutableAttributedString *attributeStr1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"数量：%@吨",self.priceStr]];
    [attributeStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3, attributeStr1.length - 3)];
    numberLab.attributedText = attributeStr1;
//    CGSize numberSize = [numberLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:numberLab.font,NSFontAttributeName,nil]];
//    numberLab.bounds = CGRectMake(0, 0, numberSize.width, 21);
    [self.contentView addSubview:numberLab];
    
    //地点的image
    UIImageView *placeView = [[UIImageView alloc] initWithFrame:CGRectMake(21, priceLab.bottom + 10 + 3, 10, 15)];
    placeView.image = [UIImage imageNamed:@"地址"];
    [self.contentView addSubview:placeView];
    
//    //placeLab
   UILabel *placeLab = [[UILabel alloc] initWithFrame:CGRectMake(placeView.right + 5, numberLab.bottom + 10, ([UIScreen mainScreen].bounds.size.width - 54) / 2 - 5, 21)];
    placeLab.font = [UIFont systemFontOfSize:16];
    placeLab.text = [NSString stringWithFormat:@"交割地:%@",self.placeStr];
    [self.contentView addSubview:placeLab];
    
    //交货的方式图片
    UIImageView *jiaohuoImage = [[UIImageView alloc] initWithFrame:CGRectMake(placeLab.right + 10, placeView.y, 10, 15)];
    jiaohuoImage.image = [UIImage imageNamed:@"接收"];
    [self.contentView addSubview:jiaohuoImage];
    
    //交货的方式
    UILabel *jiaohuoLab = [[UILabel alloc] initWithFrame:CGRectMake(jiaohuoImage.right + 5, placeLab.y, placeLab.width, 21)];
    jiaohuoLab.font = [UIFont systemFontOfSize:16];
    jiaohuoLab.text = [NSString stringWithFormat:@"交货方式:%@",self.jiaohuoStr];
    [self.contentView addSubview:jiaohuoLab];
    
    //修饰线2
    UIView *v3 = [[UIView alloc] initWithFrame:CGRectMake(0, jiaohuoLab.bottom + 10, [UIScreen mainScreen].bounds.size.width, 1)];
    v3.backgroundColor = dockwhite_;
    [self.contentView addSubview:v3];
    
    //总价啊
    UILabel *totalPriceLab = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 181, v3.bottom + 10, 160, 21)];
    totalPriceLab.font = [UIFont systemFontOfSize:16];
    NSMutableAttributedString *totalPriceStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"总价：%@元",self.totalpriceStr]];
    [totalPriceStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3, totalPriceStr.length - 3)];
    totalPriceLab.attributedText = totalPriceStr;
    totalPriceLab.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:totalPriceLab];

}
- (void)setModel:(BGShellerOrderListListAddayModel *)model
{
    _model = model;
    self.orderStr = model.idStr;
    self.leibieStr = model.title;
    self.timeStr = model.add_time;
    self.priceStr = model.price;
    self.numberStr = model.number;
    self.placeStr = model.delivery_area;
    self.jiaohuoStr = model.delivery_type_str;
    self.totalpriceStr = model.total_price;
    self.typeStr = model.pay_status;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    BGSellerOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentify];
    if (!cell) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentify];
    }
    return cell;
    
}
@end
